package com.burst.reptile.modular.system.entity;

import java.time.LocalDateTime;
import java.util.List;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.burst.reptile.common.constant.Constants;
import com.burst.reptile.framework.aspectj.lang.annotation.Excel;
import com.burst.reptile.framework.aspectj.lang.annotation.Excel.ColumnType;
import com.burst.reptile.framework.aspectj.lang.annotation.Excel.Type;
import com.burst.reptile.framework.aspectj.lang.annotation.Excels;
import com.burst.reptile.framework.web.entity.BaseEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * <p>
 * 用户信息表
 * </p>
 *
 * @author wujin
 * @since 2020-05-21
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("sys_user")
public class SysUser extends BaseEntity {

	private static final long serialVersionUID = 1L;

	/**
	 * 用户ID
	 */
	@TableId(value = "user_id", type = IdType.AUTO)
	@Excel(name = "用户序号", cellType = ColumnType.NUMERIC, prompt = "用户编号")
	private Long userId;

	/**
	 * 部门ID
	 */
	@Excel(name = "部门编号", type = Type.IMPORT)
	private Long deptId;

	/**
	 * 用户账号
	 */
	@NotBlank(message = "用户账号不能为空")
	@Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符")
	@Excel(name = "登录名称")
	private String userName;

	/**
	 * 用户昵称
	 */
	@Size(min = 0, max = 30, message = "用户昵称长度不能超过30个字符")
	@Excel(name = "用户名称")
	private String nickName;

	/**
	 * 用户类型（00系统用户）
	 */
	private String userType;

	/**
	 * 用户邮箱
	 */
	@Email(message = "邮箱格式不正确")
	@Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符")
	@Excel(name = "用户邮箱")
	private String email;

	/**
	 * 手机号码
	 */
	@Size(min = 0, max = 11, message = "手机号码长度不能超过11个字符")
	@Excel(name = "手机号码")
	private String phonenumber;
	
	/**
	 * 生日
	 */
	private String birthday;
	
	/**
	 * 区域
	 */
	private String region;
	
	/**
	 * 背景图
	 */
	private String backmap;

	/**
	 * 用户性别（0男 1女 2未知）
	 */
	@Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知")
	private String sex;

	/**
	 * 头像地址
	 */
	private String avatar = Constants.DEFAULT_AVATAR;

	/**
	 * 密码
	 */
	private String password;
	
	/**
	 * 用户标签
	 */
	private String label;
	
	/**
	 * 业态ID
	 */
	private Integer formatId;
	
	/**
	 * 店铺地址
	 */
	@Size(min = 0, max = 50, message = "店铺地址不能超过50个字符")
	private String shopName;

	/**
	 * 帐号状态（0正常 1停用）
	 */
	@Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
	private String userStatus;

	/**
	 * 删除标志（0逻辑未删除值 1逻辑已删除值）
	 */
	@TableLogic
	private String delFlag;

	/**
	 * 最后登陆IP
	 */
	@Excel(name = "最后登陆IP", type = Type.EXPORT)
	private String loginIp;

	/**
	 * 最后登陆时间
	 */
	@Excel(name = "最后登陆时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
	private LocalDateTime loginTime;

	/**
     * 备注
     */
	private String remark;

	/**
	 * 部门对象
	 */
	@TableField(exist = false)
	@Excels({ @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
			@Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT) })
	private SysDept dept;

	/**
	 * 角色对象
	 */
	@TableField(exist = false)
	private List<SysRole> roles;

	/**
	 * 角色组
	 */
	@TableField(exist = false)
	private Long[] roleIds;

	/**
	 * 岗位组
	 */
	@TableField(exist = false)
	private Long[] postIds;
	
	/**
	 * 粉丝量
	 */
	@TableField(exist = false)
	private String fans;
	
	/**
	 * 关注量
	 */
	@TableField(exist = false)
	private String follow;
	
	/**
	 * 点赞量
	 */
	@TableField(exist = false)
	private String like;
	
	/**
	 * 获赞量
	 */
	@TableField(exist = false)
	private String bePraised;
	
	/**
	 * 发布量
	 */
	@TableField(exist = false)
	private String releaseVolume;
	
	/**
	 * 收藏量
	 */
	@TableField(exist = false)
	private String collection;
	
	/**
	 * 草稿数量
	 */
	@TableField(exist = false)
	private Integer draftsNum;
	
	/**
	 * 是否关注
	 */
	@TableField(exist = false)
	private boolean mutual;
	
	/**
	 * 业态名称
	 */
	@TableField(exist = false)
	private String formatName;
	
	/**
	 * 未读消息数量
	 */
	@TableField(exist = false)
	private Integer msgNum;
	
	/**
	 * 未读消息数量
	 */
	@TableField(exist = false)
	private Integer privateLetterNum;

	public boolean isAdmin() {
		return isAdmin(this.userId);
	}

	public static boolean isAdmin(Long userId) {
		return userId != null && 1L == userId;
	}

}
